﻿using System;
using System.Windows;
using System.Windows.Media; //transform
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Multitouch.Framework.WPF.Input;
using Project_CFT2.View;
using Project_CFT2.ViewModel;


namespace Project_CFT2.Factory
{
    class furnitureFactory : IPanelViewFactory
    {

        public Panel Panel { get; set; }

        public void CreateViewFromDataContext(object dataContext, Point position)
        {

            FrameworkElement newView;
            
            /*
                        newView = new Trash();
                        newView.SetValue(Canvas.LeftProperty, position.X);
                        newView.SetValue(Canvas.TopProperty, position.Y);
                        MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                        Panel.Children.Add(newView);
                        */
            var viewModel = dataContext as ViewModelBase;
            if (viewModel is FurnitureViewModel)    
            {
               

                newView = new FurnitureObjectView();
                
                
                newView.DataContext = viewModel;
                //newView = new FurnitureView();
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);

                

                MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                //MultitouchScreen.AddContactLeaveHandler(newView, ElementLeaveHandler);
                //MultitouchScreen.AddContactEnterHandler(newView, ElementFocusHandler);
                Panel.Children.Add(newView);
                //   newView = new FeedItemView();
            }
            else if (viewModel is FurnitureViewModel2)
            {


                newView = new FurnitureObjectView2();


                newView.DataContext = viewModel;
                //newView = new FurnitureView();
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);



                MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                //MultitouchScreen.AddContactLeaveHandler(newView, ElementLeaveHandler);
                //MultitouchScreen.AddContactEnterHandler(newView, ElementFocusHandler);
                Panel.Children.Add(newView);
                //   newView = new FeedItemView();
            }
            else if(viewModel is FolderViewModel)
            {

                TransformGroup trGrp = new TransformGroup();
                RotateTransform trRot;
                trRot = new RotateTransform(0);
                trRot.Angle = 50;
                trGrp.Children.Add(trRot);
                //used to initially create objects
                newView = new FurnitureView();
                
                newView.DataContext = viewModel;
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);
                
              //  MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                
                Panel.Children.Add(newView);

            }
            else if (viewModel is FolderViewModel2)
            {

                TransformGroup trGrp = new TransformGroup();
                RotateTransform trRot;
                trRot = new RotateTransform(0);
                trRot.Angle = 50;
                trGrp.Children.Add(trRot);
                //used to initially create objects
                newView = new FurnitureView2();

                newView.DataContext = viewModel;
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);

              //  MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);

                Panel.Children.Add(newView);

            }
            else if (viewModel is RoomViewModel)
            {

                newView = new RoomView();
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);
               // MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                Panel.Children.Add(newView);

                //FrameworkElement newView2;
                //newView2 = new DynamicGeometry.DrawingHost();

                ////MultitouchScreen.AddGotContactCaptureHandler(newView2, ElementCaptureHandler);
                ////newView2 = new DynamicGeometry.Window1();
                
                //newView2.SetValue(Canvas.LeftProperty, position.X);
                //newView2.SetValue(Canvas.TopProperty, position.Y);
                ////MultitouchScreen.AddContactEnterHandler(newView2, ElementCaptureHandler);
                //Panel.Children.Add(newView2);


                //FrameworkElement newView3;
                //newView3 = new FurniturePopupView();
                //newView3.SetValue(Canvas.LeftProperty, position.X + 100);
                //newView3.SetValue(Canvas.TopProperty, position.Y + 800);
                
                //Panel.Children.Add(newView3);

                

            }
            
        }
        public void CreateViewFromDataContext2(object dataContext, Point position, Panel p)
        {
            
            
                        
            FrameworkElement newView;
            /*
                        newView = new Trash();
                        newView.SetValue(Canvas.LeftProperty, position.X);
                        newView.SetValue(Canvas.TopProperty, position.Y);
                        MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                        Panel.Children.Add(newView);
                        */
            var viewModel = dataContext as ViewModelBase;
            if (viewModel is FurnitureViewModel)
            {
                //Panel = ElementCaptureHandler as Panel;

                newView = new FurnitureObjectView();
                newView.DataContext = viewModel;
                newView = new FurnitureView();
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.LeftProperty, position.Y);
               
                MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                
                p.Children.Add(newView);
                
                
                
                ///MessageBox.Show();
                //   newView = new FeedItemView();
            }
            else if (viewModel is FolderViewModel)
            {

                //used to initially create objects
                newView = new FurnitureView();

                newView.DataContext = viewModel;
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.TopProperty, position.Y);
                MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                Panel.Children.Add(newView);

            }
            else if (viewModel is RoomViewModel)
            {
                newView = new RoomView();
                newView.SetValue(Canvas.LeftProperty, position.X);
                newView.SetValue(Canvas.RightProperty, position.Y);
                MultitouchScreen.AddContactEnterHandler(newView, ElementCaptureHandler);
                Panel.Children.Add(newView);
            }

        }

        private static void ElementCaptureHandler(object sender, ContactEventArgs e)
        {

            var element = sender as IInputElement;

            if (element != null)
            {
                e.Contact.Capture(element);
                
                
                //element.CaptureMouse();
            }
                
        }
        
     
    }
}
